package com.stepshop.wechat.utils;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.TreeMap;

import org.jdom.JDOMException;

public class TestMain {
	private String url = "https://api.mch.weixin.qq.com/pay/unifiedorder";  
    private String charset = "utf-8";  
    private HttpClientUtil httpClientUtil = null;  
      
    public TestMain(){  
        httpClientUtil = new HttpClientUtil();  
    }  
      
    public void test(){  
//        String httpOrgCreateTest = url + "";  
//        Map<String,String> createMap = new HashMap<String,String>();  
//        createMap.put("authuser","*****");  
//        createMap.put("authpass","*****");  
//        createMap.put("orgkey","****");  
//        createMap.put("orgname","****");  
//        String httpOrgCreateTestRtn = httpClientUtil.doPost(httpOrgCreateTest,createMap,charset);  
//        System.out.println("result:"+httpOrgCreateTestRtn);  
    }  
    public void postWithXml(){
//    	String url1="appid=wxd152167cedf23e16&attach=支付测试&body=JSAPI支付测试&mch_id=1324751901&nonce_str=1add1a30ac87aa2db72f57a2375d8fec&notify_url=http://wxpay.weixin.qq.com/pub_v2/pay/notify.v2.php&openid=oUpF8uMuAJO_M2pxb1Q9zNjWeS6o&out_trade_no=1415659990&spbill_create_ip=14.23.150.211&total_fee=1&trade_type=JSAPI";
//    	String url1="appid=wxd152167cedf23e16&attach=支付测试&body=JSAPI支付测试&mch_id=1324751901&nonce_str=1add1a30ac87aa2db72f57a2375d8fec&notify_url=http://wxpay.weixin.qq.com/pub_v2/pay/notify.v2.php&openid=oUpF8uMuAJO_M2pxb1Q9zNjWeS6o&out_trade_no=1415659990&spbill_create_ip=14.23.150.211&total_fee=1&trade_type=JSAPI&key=34234";
//    	String sign=MD5Util.MD5Encode(url1, "UTF-8").toUpperCase();
    	
    	String sign="";
    	Map<String,String> paramMaps=new TreeMap<String, String>();
    	paramMaps.put("appid", "wxd152167cedf23e16");
    	paramMaps.put("mch_id", "1324751901");
    	paramMaps.put("nonce_str", "1add1a30ac87aa2db72f57a2375d8fec");
    	paramMaps.put("attach", "支付测试");
    	paramMaps.put("body", "JSAPI支付测试");
    	paramMaps.put("out_trade_no", "1415659990");
    	paramMaps.put("total_fee", "1");
    	paramMaps.put("openid", "o3QjlwGBjeKHvc16IR-sMO8KXvec");
    	paramMaps.put("spbill_create_ip", "14.23.150.211");
    	paramMaps.put("notify_url", "http://wxpay.weixin.qq.com/pub_v2/pay/notify.v2.php");
    	//支付类型  1:JSAPI 微信公众号支付   2:扫码支付
    	paramMaps.put("trade_type", "JSAPI");
		sign = Signature.getSign(paramMaps);
		paramMaps.put("sign", sign);
		String xml = XMLUtil.map2Xml(paramMaps, "xml");
    	String string = httpClientUtil.doPost(url,xml, "UTF-8");
    	Map map=new HashMap<String, String>();
    	try {
			map = XMLUtil.doXMLParse(xml);
		} catch (Exception e) {
			e.printStackTrace();
		}
    	System.out.println(string);
    }
      
    public static void main(String[] args){  
        TestMain main = new TestMain();  
//        main.test();  
        main.postWithXml();
//    	Map<String, String> map=new HashMap<String, String>();
//    	map.put("id", "11111");
//    	map.put("name", "2222222");
//    	new  Signature().getSign(map);
    }  
}
